//@author A0096509U
#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace TaskItUnitTest {
	TEST_CLASS(TaskItStorageTest) {
	public:
		
		TEST_METHOD(testAdd) {
			TaskItStorage myStorage;
			TaskItTime eightAM, tenAM, onePM, threePM, fivePM, noTime;
			Date one, two, three, noDate;
			one.setDate(10514);
			two.setDate(150514);
			three.setDate(240514);
			eightAM.setTime("0800");
			tenAM.setTime("1000");
			onePM.setTime("1300");
			threePM.setTime("1500");
			fivePM.setTime("1700");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.addTask("Project Due", "", noTime, fivePM, "Work", one);
			myStorage.addTask("Meeting with Boss", "Conference Room", eightAM, tenAM, "Work", two);
			myStorage.addTask("Clear up storeroom", "", noTime, noTime, "Personal", two);
			Assert::AreEqual(5, myStorage.getNumOfTask());
		}

		TEST_METHOD(testSort) {
			TaskItStorage myStorage;
			TaskItTime eightAM, tenAM, onePM, threePM, fivePM, noTime;
			Date one, two, three, noDate;
			one.setDate(10514);
			two.setDate(150514);
			three.setDate(240514);
			eightAM.setTime("0800");
			tenAM.setTime("1000");
			onePM.setTime("1300");
			threePM.setTime("1500");
			fivePM.setTime("1700");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.addTask("Project Due", "", noTime, fivePM, "Work", one);
			myStorage.addTask("Meeting with Boss", "Conference Room", eightAM, tenAM, "Work", two);
			myStorage.addTask("Clear up storeroom", "", noTime, noTime, "Personal", two);
			Assert::AreEqual("Finish Harry Potter", myStorage.getTask(0).getActivity().c_str());
			Assert::AreEqual("Project Due", myStorage.getTask(1).getActivity().c_str());
			Assert::AreEqual("Clear up storeroom", myStorage.getTask(2).getActivity().c_str());
			Assert::AreEqual("Meeting with Boss", myStorage.getTask(3).getActivity().c_str());
			Assert::AreEqual("Lunch Appointment", myStorage.getTask(4).getActivity().c_str());
		}

		TEST_METHOD(testDelete) {
			TaskItStorage myStorage;
			TaskItTime eightAM, tenAM, onePM, threePM, fivePM, noTime;
			Date one, two, three, noDate;
			one.setDate(10514);
			two.setDate(150514);
			three.setDate(240514);
			eightAM.setTime("0800");
			tenAM.setTime("1000");
			onePM.setTime("1300");
			threePM.setTime("1500");
			fivePM.setTime("1700");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.addTask("Project Due", "", noTime, fivePM, "Work", one);
			myStorage.addTask("Meeting with Boss", "Conference Room", eightAM, tenAM, "Work", two);
			myStorage.addTask("Clear up storeroom", "", noTime, noTime, "Personal", two);
			myStorage.deleteTask(3);
			Assert::AreEqual(4, myStorage.getNumOfTask());
			Assert::AreNotEqual("Clear up storeroom", myStorage.getTask(0).getActivity().c_str());
			Assert::AreNotEqual("Clear up storeroom", myStorage.getTask(1).getActivity().c_str());
			Assert::AreNotEqual("Clear up storeroom", myStorage.getTask(2).getActivity().c_str());
			Assert::AreNotEqual("Clear up storeroom", myStorage.getTask(3).getActivity().c_str());
		}

		TEST_METHOD(testMark) {
			TaskItStorage myStorage;
			TaskItTime onePM, threePM, noTime;
			Date one, two, three, noDate;
			three.setDate(240514);
			onePM.setTime("1300");
			threePM.setTime("1500");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.markTask(2);
			Assert::AreEqual(false, myStorage.getTask(0).getDone());
			Assert::AreEqual(true, myStorage.getTask(1).getDone());
		}

		TEST_METHOD(testEdit) {
			TaskItStorage myStorage;
			TaskItTime onePM, threePM, noTime;
			Date one, two, three, noDate;
			two.setDate(150514);
			three.setDate(240514);
			onePM.setTime("1300");
			threePM.setTime("1500");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.editTask("Harry Potter Movie", "Shaw Lido", onePM, threePM, "Movies", two, 2);
			Assert::AreEqual("Harry Potter Movie", myStorage.getTask(1).getActivity().c_str());
			Assert::AreEqual("Shaw Lido", myStorage.getTask(1).getVenue().c_str());
			Assert::AreEqual("13:00", myStorage.getTask(1).getTimeStart().getDisplay().c_str());
			Assert::AreEqual("15:00", myStorage.getTask(1).getTimeEnd().getDisplay().c_str());
			Assert::AreEqual("Movies", myStorage.getTask(1).getCategory().c_str());
			Assert::AreEqual("150514", myStorage.getTask(1).getDate().getDisplay().c_str());
		}
		
		TEST_METHOD(testUndoAdd) {
			TaskItStorage myStorage;
			TaskItTime onePM, threePM, fivePM, noTime;
			Date one, two, three, noDate;
			one.setDate(10514);
			two.setDate(150514);
			three.setDate(240514);
			onePM.setTime("1300");
			threePM.setTime("1500");
			fivePM.setTime("1700");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Project Due", "", noTime, fivePM, "Work", one);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.undoTask();
			Assert::AreNotEqual("Finish Harry Potter", myStorage.getTask(0).getActivity().c_str());
			Assert::AreNotEqual("Finish Harry Potter", myStorage.getTask(1).getActivity().c_str());
		}

		TEST_METHOD(testUndoDelete) {
			TaskItStorage myStorage;
			TaskItTime onePM, threePM, fivePM, noTime;
			Date one, two, three, noDate;
			one.setDate(10514);
			two.setDate(150514);
			three.setDate(240514);
			onePM.setTime("1300");
			threePM.setTime("1500");
			fivePM.setTime("1700");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Project Due", "", noTime, fivePM, "Work", one);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.deleteTask(3);
			myStorage.undoTask();
			Assert::AreEqual("Finish Harry Potter", myStorage.getTask(0).getActivity().c_str());
			Assert::AreEqual("Project Due", myStorage.getTask(1).getActivity().c_str());
			Assert::AreEqual("Lunch Appointment", myStorage.getTask(2).getActivity().c_str());
		}
		
		TEST_METHOD(testUndoEdit) {
			TaskItStorage myStorage;
			TaskItTime onePM, threePM, fivePM, noTime;
			Date one, two, three, noDate;
			one.setDate(10514);
			two.setDate(150514);
			three.setDate(240514);
			onePM.setTime("1300");
			threePM.setTime("1500");
			fivePM.setTime("1700");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Project Due", "", noTime, fivePM, "Work", one);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.editTask("Harry Potter Movie", "Shaw Lido", fivePM, noTime, "Movies", two, 3);
			myStorage.undoTask();
			Assert::AreEqual("Lunch Appointment", myStorage.getTask(2).getActivity().c_str());
			Assert::AreEqual("Breadyard", myStorage.getTask(2).getVenue().c_str());
			Assert::AreEqual("13:00", myStorage.getTask(2).getTimeStart().getDisplay().c_str());
			Assert::AreEqual("15:00", myStorage.getTask(2).getTimeEnd().getDisplay().c_str());
			Assert::AreEqual("Personal", myStorage.getTask(2).getCategory().c_str());
			Assert::AreEqual("240514", myStorage.getTask(2).getDate().getDisplay().c_str());
		}

		TEST_METHOD(testUndoMark) {
			TaskItStorage myStorage;
			TaskItTime onePM, threePM, noTime;
			Date one, two, three, noDate;
			three.setDate(240514);
			onePM.setTime("1300");
			threePM.setTime("1500");
			myStorage.addTask("Lunch Appointment", "Breadyard", onePM, threePM, "Personal", three);
			myStorage.addTask("Finish Harry Potter", "", noTime, noTime, "Leisure", noDate);
			myStorage.markTask(2);
			myStorage.undoTask();
			Assert::AreEqual(false, myStorage.getTask(0).getDone());
			Assert::AreEqual(false, myStorage.getTask(1).getDone());
		}


	};
}